/*
 * @Author: superRice
 * @Date: 2025-04-27 11:23:07
 * @LastEditors: superRice 1246333567@qq.com
 * @LastEditTime: 2025-04-28 15:25:49
 * @FilePath: /threejs-testing-dedicated/examples/testSprite/index.js
 * @Description:
 * Do your best to be yourself
 * Copyright (c) 2025 by superRice, All Rights Reserved.
 */
import * as TE from 'TEngine';
import * as THREE from 'three';
import { Pane } from 'tweakpane';
import { CustomSprite } from './CustomSprite';
import { CustomSpriteMaterial } from './CustomSpriteMaterial';
const TS = new TE.TEngine();
TS.camera.position.set(10, 10, 10);
TS.camera.lookAt(0, 0, 0);

const axes = new THREE.AxesHelper(5);
TS.scene.add(axes);

//先创建一个方格
const box = new THREE.Mesh(
  new THREE.BoxGeometry(1, 1, 1),
  new THREE.MeshBasicMaterial({ color: 'red', wireframe: true }),
);

box.position.set(0, 0, 0);
// TS.scene.add(box);

//导入一个图片，转换成canvasTexture
const canvas = document.createElement('canvas');

const ctx = canvas.getContext('2d');
const image = new Image();
image.src = '/public/texture/未标题-1.png';
image.onload = () => {
  canvas.width = image.width;
  canvas.height = image.height;
  ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
  const texture = new THREE.CanvasTexture(canvas);
  texture.needsUpdate = true;
  //创建一个sprite
  const sprite = new CustomSprite(
    new CustomSpriteMaterial({
      map: texture,
      // transparent: false,
      // depthTest: false,
      // alphaTest: 0.5,
    }),
    canvas.width / 1000,
    canvas.height / 1000,
    'center',
  );
  // sprite.scale.setScalar(0.01);

  TS.scene.add(sprite);
};
